<template>
	<view class="bg">
		<view class="nav">
			<view class="circle"></view>
			<view class="title">
				{{title}}
			</view>
			<view class="data">
				共<span style="color: #9B2033;">{{prizes.length}}</span>项，总加分：<span
					style="color: #9B2033;">{{total}}</span>分
			</view>
		</view>
		<view class="controls">
			<view class="date-container">
				<uni-data-select v-model="year" :localdata="years" @change="onYearChange"></uni-data-select>
			</view>
			<button class="btn" type="warn" size="mini">导出</button>
		</view>
		<view class="card-list">
			<view v-if="currentPrizes.length==0" class="omit">
				暂无证明材料
			</view>
			<view class="card" v-for="(item,index) in currentPrizes" :key="index">
				<image class="card-image" :src="getOnlineImage(item.url)"
					mode="aspectFill"></image>
				<view class="card-right">
					<view class="score">
						获得加分：{{item.score}}

					</view>
					<view class="prize">
						奖项：{{item.prize}}
					</view>
					<view class="time">
						时间：{{item.date}}
					</view>

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				year: 0,
				years: [],
				total: 9,
				prizes: [],
				currentPrizes: [],
				title:'学术与竞赛证明',
				type:'scholar'
			}
		},
		onLoad(config) {
			console.log(config)
			if(config.type=="comprehen"){
				this.type='comprehen'
				this.title='综合素质证明';
			}
			const API_BASE_URL = this.$ProjectConfig.API_BASE_URL;
			const this2 = this;
			wx.request({
				url: API_BASE_URL + '/material/materialDetail',
				method: 'GET',
				header: {
				  'Content-Type': 'application/json',
				},
				data: {
				    user_id:uni.getStorageSync("user_id"),
					type:this2.type
				},
				success: function(res) {
					console.log(res);
					this2.prizes=res.data;
					this2.currentPrizes = this2.prizes;
					this2.total = 0;
					this2.prizes.forEach((item) => {
						this2.total += item.score;
						this2.years.push({value:item.date.substring(0, 4),text:item.date.substring(0, 4)})
					})
				}
			});
		},
		computed:{
			getOnlineImage: function() {
			  return function(path) {
				return this.$ProjectConfig.STATIC_BASE_URL + path;
			  };
			}
		},
		methods: {
			onYearChange(e) {
				console.log(e);
				
				if(e==""){
					this.currentPrizes = this.prizes;
					return;
				}
				
				this.currentPrizes = [];
				const that = this;
				this.prizes.forEach((item) => {
					console.log(item.date.substring(0, 4));
					if (item.date.substring(0, 4) == that.year.toString())
						that.currentPrizes.push(item);
				})
			}
		}
	}
</script>

<style lang="scss">
	.bg {
		background-color: #fff;

	}

	.nav {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx 30rpx;

		.circle {
			height: 16rpx;
			width: 16rpx;
			border: 4rpx solid #9B2033;
			border-radius: 10rpx;
			margin-right: 20rpx;
		}

		.title {
			font-size: 35rpx;
			font-weight: 700;
			margin-right: 40rpx;
		}

		.data {
			font-size: 30rpx;

		}
	}

	.controls {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx 30rpx;

		.date-container {
			width: 80%;
		}
	}
	.omit{
		font-size: $uni-font-size-lg;
		color:#AAA;
		text-align: center;
	}
	.card-list {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin: 20rpx 0;

		.card {
			box-sizing: border-box;
			display: flex;
			flex-direction: row;
			align-items: center;
			width: 90%;
			height: 300rpx;
			padding: 20rpx;
			margin-bottom: 20rpx;
			border-radius: 10rpx;
			box-shadow: 0 2rpx 6rpx 2rpx rgba(0, 0, 0, 0.15);
			background-color: #fff;

			.card-image {
				width: 40%;
				height: 80%;
				margin-right: 30rpx;
			}

			.card-right {
				font-size: $uni-font-size-base;
				line-height: 2.5;
				
				color: #333;
			}
		}
	}
</style>